package com.uchengwang.ui.cm_ui.ucity.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.functions.image.ImageManager;
import com.uchengwang.ui.cm_ui.ucity.cityBean.UcityInfoBean;
import com.uchengwang.ui.utils.DateUtil;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2017/3/13.
 * 校园热门推荐Adapter
 */

public class CitySchoolHotAdapter extends RecyclerView.Adapter<CitySchoolHotAdapter.CitySchoolHotVH>{
    private Context context;
    private List<UcityInfoBean> list = new ArrayList<>();

    public CitySchoolHotAdapter(Context context){
        this.context = context;
    }

    public void setData(List<UcityInfoBean> list){
        this.list = list;
        notifyDataSetChanged();

    }

    public List<UcityInfoBean> getData(){
        return list;
    }


    @Override
    public CitySchoolHotVH onCreateViewHolder(ViewGroup parent, int viewType) {
        //根据viewtype加载不同的界面
        View view  = LayoutInflater.from(context).inflate( R.layout.club_activity_item, parent, false);;

        return new CitySchoolHotVH(view);
    }

    @Override
    public void onBindViewHolder(CitySchoolHotVH holder, int position) {
        final UcityInfoBean bean = list.get(position);
        ImageManager.getInstance().loadImage(context, holder.image, bean.getPubShortCover(), ImageManager.ImageType.ROUND);
        holder.name.setText(bean.getNickName());
        holder.title.setText(bean.getPubTitle());
        holder.content.setText(bean.getPubDescription());
        holder.location.setText(bean.getPubAddr());

        holder.time.setText(DateUtil.getDateUtil().getDateByMillis(DateUtil.DATE_FORMAT_MDHM, bean.getStartTime()));

        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //1-U学，2-U赛，3-U行，4-U用，7-社团活动,
                //5-U公益活动倡议，6-U公益失物招领, 8-社团分享) 9校吧帖子
                Intent intent = null;
                switch (bean.getPubType()){
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                    case 7:
//                        intent = new Intent(context, UCity3Activity.class);
//                        intent.putExtra(BaseConfig.ID, bean.getId());
//                        intent.putExtra(BaseConfig.PUB_TYPE, bean.getPubType());
                        break;
                    case 5:
                    case 8:
                    case 9:
//                        intent = new Intent(context, SchoolNewDetailActivity.class);
//                        intent.putExtra(BaseConfig.ID, bean.getId());
                        break;
                }
                if (intent != null){
                    context.startActivity(intent);
                }
            }
        });



    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class CitySchoolHotVH extends RecyclerView.ViewHolder{

        private View view;
        private TextView title, content, location, time, line, like_num;
        private TextView name;
        private ImageView image, like_image;
        private LinearLayout linear_like;

        public CitySchoolHotVH(View itemView) {
            super(itemView);
            AutoUtils.autoSize(itemView);
            view = itemView;

            name = (TextView) itemView.findViewById(R.id.club_act_clubName);
            title = (TextView) itemView.findViewById(R.id.club_act_title);
            content = (TextView) itemView.findViewById(R.id.club_act_content);
            location = (TextView) itemView.findViewById(R.id.club_act_location);
            time = (TextView) itemView.findViewById(R.id.club_act_time);
            image = (ImageView) itemView.findViewById(R.id.club_act_image);
            linear_like = (LinearLayout) itemView.findViewById(R.id.club_act_like);
            linear_like.setVisibility(View.GONE);
            like_image = (ImageView) itemView.findViewById(R.id.like_image);
            like_num = (TextView) itemView.findViewById(R.id.like_num);






        }
    }
}
